package org.practice.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.IndexColumn;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
@Entity
@Table(name="shop_category")
public class Category implements java.io.Serializable{
	private static final long serialVersionUID=123465l;
	public static final int BOOK_ID=1;
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)//指定生成器的策略
	private Integer id;
	@Column(name="en_name")
	private String enName;
	private String name;
	@Column(name="description")
	private String desc;
	
	@ManyToOne
	@JoinColumn(name="parent_id")
	private Category parentCategory;

	@OneToMany(mappedBy="parentCategory",fetch=FetchType.EAGER)//FetchType.LAZY：延迟加载，FetchType.EAGER：立即加载
//	@LazyCollection(LazyCollectionOption.FALSE)
	@IndexColumn(name="turn",base=1)//对应<list-index column="turn" base="1"/>
	private List<Category> subCategory;//List集合是有序的，可重复的集合。因此list元素需要使用index来指定集合元素的次序
	public Category(){
		super();
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getEnName() {
		return enName;
	}
	public void setEnName(String enName) {
		this.enName = enName;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public Category getParentCategory() {
		return parentCategory;
	}
	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}
	public List<Category> getSubCategory() {
		return subCategory;
	}
	public void setSubCategory(List<Category> subCategory) {
		this.subCategory = subCategory;
	}
	
}
